package uilayer;

import java.util.Scanner;

/**
 * The Class MenuInputs.
 * 
 *@author Benjamin Ørskov
 *@author Lasse Lambertsen
 *@author Ole Kirk
 *@author Søren Søgaard
 */
public abstract class MenuInputs {

	/**
	 * Instantiates a new menu inputs.
	 */
	public MenuInputs() {
	}

	/**
	 * Validate int input.
	 *
	 * @return the int
	 */
	protected int validateIntInput() {
		Scanner keyboard = new Scanner(System.in);
		String tempString = keyboard.nextLine();
		int tempInt = 0;
		try {
			tempInt = Integer.parseInt(tempString);
		} catch (NumberFormatException nfe) {
			System.out.println("Indtast et tal!");
			validateIntInput();
		}
		return tempInt;
	}

	/**
	 * Validate double input.
	 *
	 * @return the double
	 */
	protected Double validateDoubleInput() {
		Scanner keyboard = new Scanner(System.in);
		String tempString = keyboard.nextLine();
		Double tempDouble = 0.0;
		try {
			tempDouble = Double.parseDouble(tempString);
		} catch (NumberFormatException nfe) {
			System.out.println("Indtast et tal!");
			validateDoubleInput();
		}
		return tempDouble;
	}

	/**
	 * Input string.
	 *
	 * @return the string
	 */
	protected String inputString() {
		Scanner keyboard = new Scanner(System.in);
		return keyboard.nextLine();
	}

	/**
	 * Input cvr.
	 *
	 * @return the string
	 */
	protected String inputCvr() {
		System.out.println(" CVR: ");
		String tempString = inputString();
		try {
			Integer.parseInt(tempString);
		} catch (NumberFormatException nfe) {
			System.out.println("CVR-nummer kan kun indholde tal!");
			inputPhone();
		}
		return tempString;
	}

	/**
	 * Input paycheck.
	 *
	 * @return the double
	 */
	protected Double inputPaycheck() {
		System.out.println(" Løn: ");
		return validateDoubleInput();
	}

	/**
	 * Input discount.
	 *
	 * @return the double
	 */
	protected Double inputDiscount() {
		System.out.println(" Rabat: ");
		return validateDoubleInput();
	}

	/**
	 * Input phone.
	 *
	 * @return the string
	 */
	protected String inputPhone() {
		System.out.println(" Telefon nummer: ");
		String tempString = inputString();
		try {
			Integer.parseInt(tempString);
		} catch (NumberFormatException nfe) {
			System.out.println("Telefon kan kun indholde tal!");
			inputPhone();
		}
		return tempString;
	}

	/**
	 * Input email.
	 *
	 * @return the string
	 */
	protected String inputEmail() {
		System.out.println(" Email: ");
		String returnString = inputString();
		if (returnString.contains("@") && returnString.contains(".")) {
			return returnString;
		} else {
			System.out.println("Email ikke korrekt!");
			inputEmail();
		}
		return returnString;
	}

	/**
	 * Input city.
	 *
	 * @return the string
	 */
	protected String inputCity() {
		System.out.println(" By: ");
		return inputString();
	}

	/**
	 * Input address.
	 *
	 * @return the string
	 */
	protected String inputAddress() {
		System.out.println(" Adresse: ");
		return inputString();
	}

	/**
	 * Input name.
	 *
	 * @return the string
	 */
	protected String inputName() {
		System.out.println(" Navn: ");
		return inputString();
	}

	/**
	 * Input type.
	 *
	 * @return the string
	 */
	protected String inputType() {
		System.out.println(" Type:  ");
		return inputString();
	}

	/**
	 * Input OrderID.
	 *
	 * @return the int
	 */
	protected int inputOrderID() {
		System.out.println(" Vare ID: ");
		return validateIntInput();
	}

	/**
	 * Input price.
	 *
	 * @return the string
	 */
	protected Double inputPrice() {
		System.out.println(" Pris: ");
		return validateDoubleInput();
	}

	/**
	 * Input salesman id.
	 *
	 * @return the int
	 */
	protected int inputSalesmanID() {
		System.out.println(" Sælger ID: ");
		return validateIntInput();
	}

	/**
	 * Input item id.
	 *
	 * @return the int
	 */
	protected int inputItemID() {
		System.out.println(" Vare ID: ");
		return validateIntInput();
	}

	/**
	 * Input amount.
	 *
	 * @return the int
	 */
	protected int inputAmount() {
		System.out.println(" Antal: ");
		return validateIntInput();
	}

	/**
	 * Input id.
	 *
	 * @return the int
	 */
	protected int inputID() {
		System.out.println(" ID: ");
		return validateIntInput();
	}

	/**
	 * Input bonus.
	 *
	 * @return the double
	 */
	protected Double inputBonus() {
		System.out.println(" Bonus ");
		return validateDoubleInput();
	}
}